<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>模型列表</title>

<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid")
				.datagrid(
						{
							title : '模型列表',
							method : "get",
							url : "${ctx}/workflow/activitiProcess/dataGrid",
							idField : 'id',
							remoteSort : true,
							multiSort : true,
							rownumbers : true,
							toolbar : '#tt',
							pagination : true,
							pageList : [ 10, 20, 30, 40, 50, 100 ],
							columns : [ [
									{
										field : 'ck',
										checkbox : true
									},
									{
										field : 'id',
										title : 'ProcessDefinitionId',
										sortable : true
									},
									{
										field : 'deploymentId',
										title : 'DeploymentId',
										sortable : true
									},
									{
										field : 'name',
										title : '名称',
										sortable : true
									},
									{
										field : 'key',
										title : 'key',
										sortable : true
									},
									{
										field : 'version',
										title : '版本号',
										sortable : true
									},
									{
										field : 'resourceName',
										title : 'xml',
										formatter : function(value, row, index) {
											return "<a target='_blank' href='${ctx }/workflow/activitiProcess/resourceRead?processDefinitionId="
													+ row.id + "&resourceType=xml'>" + value + "</a>";
										}

									},
									{
										field : 'diagramResourceName',
										title : 'diagram',
										formatter : function(value, row, index) {
											return "<a target='_blank' href='${ctx }/workflow/activitiProcess/resourceRead?processDefinitionId="
													+ row.id + "&resourceType=image'>" + value + "</a>";
										}
									},
									{
										field : 'deploymentTime',
										title : '部署时间',
									},
									{
										field : 'suspended',
										title : '是否挂起',
										formatter : function(value, row, index) {
											if (value) {
												return "是";
											} else {
												return "否";
											}
										}
									},
									{
										field : 'action',
										title : '操作',
										formatter : function(value, row, index) {
											var result = "";
											if (row.suspended) {
												result += "<a href='${ctx}/workflow/activitiProcessInstance/update/active/"+row.id+"'>激活</a>";
											} else {
												result += "<a href='${ctx}/workflow/activitiProcessInstance/update/suspend/"+row.id+"'>挂起</a>";
											}
											result += "<a href='${ctx}/workflow/activitiProcess/start?processDefinitionId="
													+ row.id + "'>启动</a>";
											return result;
										}
									} ] ],
							enableHeaderClickMenu : true, //此属性开启表头列名称右侧那个箭头形状的鼠标左键点击菜单
							enableHeaderContextMenu : true, //此属性开启表头列名称右键点击菜单
							enableRowContextMenu : false
						});
		$("#autoDeploy").click(function() {
			showConfirm("您确定要自动部署全部流程？", function(){
				$.easyui.loading({msg: "正在处理中,请耐心等候..."});
				$.get("${ctx}/workflow/activitiProcess/autoDeploy", function(result){
					$.easyui.loaded();
					if(result.success){
						$grid.datagrid("reload");
					}
					showInfo(result.msg);
				}, 'json');
			});
		});
		$("#deploy").click(function() {
			$("#fm").form("clear");
			$("#dlg").dialog("open").dialog("setTitle", "部署新流程");
		});
		$("#convert")
				.click(
						function() {
							var rowData = $grid.datagrid("getSelected");
							if (rowData == null) {
								$.messager.show({
									msg : "请您先选中行",
									icon : "warning",
									position : "bottomRight"
								});
							} else {
								window
										.open("${ctx}/workflow/activitiProcess/convertToModel/"
												+ rowData.id);
							}
						});
		$("#delete").click(
				function() {
					var rowData = $grid.datagrid("getSelected");
					if (rowData == null) {
						$.messager.show({
							msg : "您未选中行，无法删除",
							icon : "warning",
							position : "bottomRight"
						});
					} else {
						$.messager.confirm("您确定要进行该操作？", function(c) {
							if (c) {
								$.get(
										"${ctx}/workflow/activitiProcess/delete?deploymentId="
												+ rowData.deploymentId,
										function(result) {
											$.messager.show({
												msg : result.msg,
												icon : "info",
												position : "bottomRight"
											});
											if (result.success) {
												$grid.datagrid("deleteRow",
														rowData);
											}
										}, 'json');
							}
						});
					}
				});
	});
</script>
</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
	<div class="col-md-4">
	<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="modelName" placeholder="模型名称" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
		</div>
		<div class="col-md-8">
			<button id="autoDeploy" type="button" class="btn btn-warning">
				<span class="glyphicon glyphicon-star-empty"></span> 自动部署
			</button>
			<button id="deploy" type="button" class="btn btn-danger">
				<span class="glyphicon glyphicon-cog"></span> 部署模型
			</button>
			<button id="convert" type="button" class="btn btn-danger">
				<span class="glyphicon glyphicon-sort"></span> 转为模型
			</button>
			<button id="delete" type="button" class="btn btn-danger">
				<span class="glyphicon glyphicon-minus"></span> 删除模型
			</button>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 400px; height: 200px; padding: 10px 20px"
		data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">		
			<div>
				<b>支持文件格式：</b>zip、bar、bpmn、bpmn20.xml
			</div>
			<form id="fm" action="${ctx }/workflow/activitiProcess/deploy" method="post" enctype="multipart/form-data">
				<input type="file" name="file" /> <br/><input type="submit" value="Submit" />
			</form>
			<div id="dlg-btn">
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
	</div>
</body>
</html>
